package mutsumimod.actions.deprecated;

import com.megacrit.cardcrawl.actions.utility.NewQueueCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import mutsumimod.actions.BaseAction;
import mutsumimod.patches.CopyPatch;

import java.util.ArrayList;

@Deprecated
public class CopyAction extends BaseAction {

    ArrayList<AbstractCard> cards;

    public CopyAction(AbstractCard c) {
        this.p = AbstractDungeon.player;
        this.actionType = ActionType.CARD_MANIPULATION;
        this.duration = Settings.ACTION_DUR_MED;
        this.cards = CopyPatch.AbstractCardFieldPatch.copyList.get(c);
        for(AbstractCard c2 : this.cards) {
            CopyPatch.AbstractCardFieldPatch.inCopyUse.set(c2, true); //同时更新target
        }
    }


    public void update() {
        if (this.duration == Settings.ACTION_DUR_MED) {
            CardGroup tmp = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);

            for (AbstractCard c : cards) {
                c.isGlowing = false;
                tmp.addToBottom(c);
            }

            if (tmp.isEmpty()) {
                this.isDone = true;
                return;
            }
            AbstractDungeon.gridSelectScreen.open(tmp, 1, false, "选择一张卡牌");
            tickDuration();
            return;
        }

        if (!AbstractDungeon.gridSelectScreen.selectedCards.isEmpty()) {
            for(AbstractCard c : cards) {
                if(AbstractDungeon.gridSelectScreen.selectedCards.contains(c)){
                    addToBot(new NewQueueCardAction(c,true,true,true));
                }else{
                    //CopyPatch.AbstractCardFieldPatch.inCopyUse.set(c, false);
                }
            }
            AbstractDungeon.gridSelectScreen.selectedCards.clear();
        }
        for (AbstractCard c : p.hand.group) {
            c.isGlowing = true;
        }
        tickDuration();
    }



}
